﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Abp.Ids4.Configuration;
using Abp.Ids4.Web;

namespace Abp.Ids4.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class Ids4DbContextFactory : IDesignTimeDbContextFactory<Ids4DbContext>
    {
        public Ids4DbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<Ids4DbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            Ids4DbContextConfigurer.Configure(builder, configuration.GetConnectionString(Ids4Consts.ConnectionStringName));

            return new Ids4DbContext(builder.Options);
        }
    }
}
